# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution(object):
    def findSecondMinimumValue(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
    #     a = set()
    #     print(a)
    #     self.find(root,a)
    #     a = sorted(a)
    #     print(a)
    #     if len(a) >1:
    #         return a[1]
    #     else:
    #         return -1
    # def find(self,node,a):
    #     if not node:
    #         return None
    #     if node.left and node.right:
    #         if node.left.val<node.right.val:
    #             a.add(node.left.val)
    #         else:
    #             a.add(node.right.val)
    #
    #     return self.find(node.left,a) or self.find(node.right,a)


        a = set()
        self.find(root,a)
        a =sorted(a)
        print(a)
        if len(a) > 1:
            return a[1]
        else:
            return -1


    def find(self,root,a):
        if not  root:
            return None
        a.add(root.val)
        return self.find(root.left, a) or self.find(root.right, a)



m1 = TreeNode(2)
m1.left = TreeNode(2)
m1.right = TreeNode(5)
# m1.left.right = TreeNode(2)
m1.right.left = TreeNode(5)
m1.right.right = TreeNode(7)

s = Solution()

t = s.findSecondMinimumValue(m1)
print(t)

